define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {

		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_getbannerlist(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"associate": [' +
					'{"associate_id": 1,"associate_type": "type_A","image_id": "./img/upload/siwper-img00.png","d_order": 1},' +
					'{"associate_id": 2,"associate_type": "type_A","image_id": "./img/upload/siwper-img01.png","d_order": 2},' +
					'{"associate_id": 2,"associate_type": "type_A","image_id": "./img/upload/siwper-img02.png","d_order": 3}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_supplier_search(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"data": [' +
					'{"store_id": 1,"store_name": "五金一店","company_profile": "各类五金专卖","company_region": "上海宝山区","company_ctel": "62123456","company_addr": "宝山区上大路","image_place1": "./img/upload/pro-img01.jpg"},' +
					'{"store_id": 2,"store_name": "五金二店","company_profile": "各类五金专卖","company_region": "上海宝山区","company_ctel": "62123456","company_addr": "宝山区上大路","image_place1": "./img/upload/pro-img01.jpg"},' +
					'{"store_id": 3,"store_name": "五金三店","company_profile": "各类五金专卖","company_region": "上海宝山区","company_ctel": "62123456","company_addr": "宝山区上大路","image_place1": "./img/upload/pro-img01.jpg"},' +
					'{"store_id": 4,"store_name": "五金四店","company_profile": "各类五金专卖","company_region": "上海宝山区","company_ctel": "62123456","company_addr": "宝山区上大路","image_place1": "./img/upload/pro-img01.jpg"},' +
					'{"store_id": 5,"store_name": "五金五店","company_profile": "各类五金专卖","company_region": "上海宝山区","company_ctel": "62123456","company_addr": "宝山区上大路","image_place1": "./img/upload/pro-img01.jpg"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_brand_getlist(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"brand": [' +
					'{"brand_id": 1,"brand_logo": "./img/upload/siwper-img00.png","brand_name": "世达五金","brand_url": "www.shidawujin.com"},' +
					'{"brand_id": 2,"brand_logo": "./img/upload/siwper-img01.png","brand_name": "世达五金","brand_url": "www.shidawujin.com"},' +
					'{"brand_id": 3,"brand_logo": "./img/upload/siwper-img02.png","brand_name": "世达五金","brand_url": "www.shidawujin.com"},' +
					'{"brand_id": 4,"brand_logo": "./img/upload/siwper-img00.png","brand_name": "世达五金","brand_url": "www.shidawujin.com"},' +
					'{"brand_id": 5,"brand_logo": "./img/upload/siwper-img02.png","brand_name": "世达五金","brand_url": "www.shidawujin.com"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_news_getlist(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_count": "500","data": [' +
					'[{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"}],' +
					'[{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"}]' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_hots_getlist(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_count": "500","data": [' +
					'[{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"}],' +
					'[{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1","store_name": "五金一店","image": "./img/upload/pro-img01.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"}]' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_mail_count(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"mail_count": 1，"mail_type": 1},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		//返回信息
		return {
			//未读消息数量
			getmailcount: function(kind, callback) {
				Http.postHide({
						method: 'member.homepagemail.getcount',
						mail_type: 1,
						kind: kind
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_mail_count(result));
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//轮播图 固定的不需要界面传参数
			getbannerlist: function(callback) {
				Http.post({
						method: 'homepage.banner.getbannerlist',
						picSize: 'CS',
						pagelimit: 8,
						nPage: 1
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_getbannerlist(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//固定菜单
			getfixmenulist: function(callback) {
				var data = new Object();
				data.normal = [
//				{
//					"img": "./img/icon-00.png",
//					"title": "新品上线",
//					"value": "newpropromotions",
//					"user_type": "5"
//				},
				{
					"img": "./img/guilin/home/menu/icon_1@2x.png",
					"title": "行业信息",
					"value": "show",
					"user_type": "5"
				}, 
//				{
//					"img": "./img/icon-03.png",
//					"title": "行业排名",
//					"value": "industryrankings",
//					"user_type": "5"
//				}, 
				{
					"img": "./img/guilin/home/menu/icon_2@2x.png",
					"title": "产品顾问",
					"value": "proconsult",
					"user_type": "5"
				}, {
					"img": "./img/guilin/home/menu/icon_3@2x.png",
					"title": "人才市场",
					"value": "recruitment",
					"user_type": "5"
				}, {
					"img": "./img/guilin/home/menu/icon_4@2x.png",
					"title": "求购信息",
					"value": "searchorder",
					"user_type": "5"
				}, {
					"img": "./img/guilin/home/menu/icon_5@2x.png",
					"title": "招商代理",
					"value": "agent",
					"user_type": "4"
				}, {
					"img": "./img/guilin/home/menu/icon_6@2x.png",
					"title": "明星企业",
					"value": "star",
					"user_type": "5"
				},{
					"img": "./img/guilin/home/menu/icon_7@2x.png",
					"title": "会员专享",
					"value": "themember",
					"user_type": "4"
				}, {
					"img": "./img/guilin/home/menu/icon_8@2x.png",
					"title": "二手/租赁",
					"value": "unsalableused",
					"user_type": "5"
				},{
					"img": "./img/guilin/home/menu/icon_9@2x.png",
					"title": "交流互动",
					"value": "exchange_interaction",
					"user_type": "5"
				},{
					"img": "./img/guilin/home/menu/icon_10@2x.png",
					"title": "培训支持",
					"value": "train",
					"user_type": "4"
				}
//				, {
//					"img": "./img/icon-13.png",
//					"title": "浏览量",
//					"value": "previewamount",
//					"user_type": "5"
//				}
				];
				//函数回调
				if(callback)
					callback(data);
			},
			//取得登录用户对应的供应商列表
			supplier_search: function(callback) {
				Http.post({
						method: 'member.supplier.search'
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_supplier_search(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//获取首页热门品牌列表
			brand_getlist: function(params, callback) {
				Http.post({
						method: 'homepage.brand.getlist',
						picSize: 'CS',
						pagelimit: 9,
						nPage: 1,
						nPage: params.nPage
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_brand_getlist(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//取得推荐的新品商品列表(地区有关)
			news_getlist: function(params, callback) {
				Http.post({
						method: 'goods.search.getlist',
						cat_type: 3,
						orderby: 1,
						picSize: 'CS',
						pagelimit: 3,
						nPage: params.nPage
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_news_getlist(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//热销商品列表
			getHotList: function(nPage, callback, calldone) {
				Http.post({
						method: 'goods.search.sellgoods',
						nPage: nPage
					},
					function(result) {
						if(callback)
							callback(result.result);
					},
					function(e) {
						//请求异常
					},
					function() {
						if(calldone)
							calldone();
					}
				);
			},
			//收藏商品
			favoriteadd_getlist: function(params, callback, failback) {
				Http.post({
						method: 'member.favorite.addgoods',
						goods_id: params.goods_id
					},
					function(result) {
						if(result.success) {
							//请求成功
							if(callback)
								callback(result.result);
						} else {
							if(failback)
								failback();
						}
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//收藏商品
			favoritedel_getlist: function(params, callback, failback) {
				Http.post({
						method: 'member.favorite.delgoods',
						goods_id: params.goods_id
					},
					function(result) {
						if(result.success) {
							//请求成功
							if(callback)
								callback(result.result);
						} else {
							if(failback)
								failback();
						}
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//百度坐标获取地区
			getarea_location: function(params, callback, failback) {
				Http.post({
						method: 'position.getarea.location',
						longitude: params.longitude,
						latitude: params.latitude
					},
					function(result) {
						if(result.success) {
							//请求成功
							if(callback)
								callback(result.result);
						} else {
							if(failback)
								failback();
						}
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//地区选择之后从新获取session
			get_long_lat: function(params, callback, failback) {
				Http.savecitys(params.province_name,params.city_name,params.district_name);
				Http.post({
						method: 'position.getarea.get_long_lat',
						province_name: params.province_name,
						city_name: params.city_name,
						district_name: params.district_name
					},
					function(result) {
						if(result.success) {
							//请求成功
							if(callback)
								callback(result.result);
						} else {
							if(failback)
								failback();
						}
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//获取用户信息，判断是否可以跳转到人才市场
			getUserInfo: function(callback) {
				Http.post({
					method: 'member.get'
				}, function(result) {
					if(callback)
						callback(result.result);
				}, function(e) {

				}, function() {
					
				})
			},
			//9个活动
			getActivities: function(callback) {
				Http.post({
					method: 'homepage.activity.getlist'
				}, function(result) {
					if(callback)
						callback(result.result);
				}, function(e) {

				}, function() {
					
				})
			}
			
			
		};
	}

	factory.$inject = ['Http'];
	
	return app.registerService("Home", factory);
});